//
//  LoginSuccessViewController.m
//  WangLottery
//
//  Created by 黄修勇 on 12-5-14.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "LoginSuccessViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "LoginViewController.h"
#import "RechargeViewController.h"
#import "AccountDetailViewController.h"
#import "MyLotteyViewController.h"
#import "CrashLoginViewController.h"
#import "UserInfoViewController.h"

@interface LoginSuccessViewController ()

@end

@implementation LoginSuccessViewController


@synthesize headView=_headView;
@synthesize phoneNumLabel=_phoneNumLabel;
@synthesize headImgView=_headImgView;
@synthesize accountTableView=_accountTableView;


-(void)dealloc{

    [_headView release];
    [_headImgView release];
    [_phoneNumLabel release];
    [_accountTableView release];
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self.view setBackgroundColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.96 alpha:1]];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _headView.layer.cornerRadius=8.0f;
    _headView.layer.backgroundColor=[UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.4f].CGColor;
    
    self.title=@"账户";
    
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];
    NSIndexPath *selectPath=[_accountTableView indexPathForSelectedRow];
    
    if (selectPath) {
        [_accountTableView deselectRowAtIndexPath:selectPath animated:YES];
    }
    
}

-(IBAction)doRecharge:(id)sender{

    RechargeViewController *reg=[[RechargeViewController alloc]initWithNibName:@"RechargeViewController" bundle:nil];
    [self.navigationController pushViewController:reg animated:YES];
    [reg release];
}



#pragma mark-UITableViewDataSource


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    switch (section) {
        case 0:
            return 3;
            break;
        case 1:
            return 2;
            break;
        default:
            return 0;
            break;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 40.0f;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellString=@"Login sucess";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellString];
    if (!cell) {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString] autorelease];
        cell.backgroundColor=[UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.4f];
        cell.imageView.backgroundColor=[UIColor clearColor];
        cell.textLabel.backgroundColor=[UIColor clearColor];
        
    }
    
    NSString *imgName;
    NSString *titleString;
        
    switch (indexPath.section) {
        case 0:
        {
            switch (indexPath.row) {
                case 0:
                    imgName=@"my_lottey_icon.png";
                    titleString=@"我的彩票";
                    break;
                case 1:
                    imgName=@"account_deteil_icon.png";
                    titleString=@"帐号明细";
                    break;
                case 2:
                    imgName=@"account_get_crash.png";
                    titleString=@"帐号提现";
                    break;
                default:
                    break;
            }
        }
            break;
            
        case 1:
        {
            switch (indexPath.row) {
                case 0:
                    imgName=@"peoplr_info.png";
                    titleString=@"个人资料";
                    break;
                case 1:
                    imgName=@"login_out.png";
                    titleString=@"退出登陆";
                    break;
                    
                default:
                    break;
            }
        }
            break;
        default:
            break;
    }
    
    UIImage *img=[UIImage imageNamed:imgName];
    cell.imageView.image=img;
    cell.textLabel.text=titleString;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section==0) {
        
        if (indexPath.row==0) {
            
            MyLotteyViewController *myLotty=[[MyLotteyViewController alloc]initWithNibName:@"MyLotteyViewController" bundle:nil];
            [self.navigationController pushViewController:myLotty animated:YES];
            [myLotty release];
            
        }else if (indexPath.row==1) {
            AccountDetailViewController *acc=[[AccountDetailViewController alloc]initWithNibName:@"AccountDetailViewController" bundle:nil];
            [self.navigationController pushViewController:acc animated:YES];
            [acc release];
        }else if(indexPath.row==2)
        {
            CrashLoginViewController *crash=[[CrashLoginViewController alloc]initWithNibName:nil bundle:nil];
            [self.navigationController pushViewController:crash animated:YES];
            [crash release];
        }
    }else if(indexPath.section==1){
    
        if (indexPath.row==0) {
            UserInfoViewController *user=[[UserInfoViewController alloc]initWithNibName:@"UserInfoViewController" bundle:nil];
            [self.navigationController pushViewController:user animated:YES];
            [user release];
            
        }else if (indexPath.row==1) {
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"确认退出登陆" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"确定", nil];
            [alert show];
            [alert release];
        }
    }
}

#pragma mark-UIAlertDelegate

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex==1) {
        LoginViewController *login=[[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
        NSArray *array=[NSArray arrayWithObject:login];
        [login release];
        
        [self.navigationController setViewControllers:array animated:YES];
    }
}
@end
